package net.sdd.vod.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sdd.common.result.Result;
import net.sdd.vod.utils.AliyunSdkUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "视频管理")
@RestController
@RequestMapping("/vod/video")
@CrossOrigin
public class VideoController {
    @Autowired
    private AliyunSdkUtils aliyunSdkUtils;

    @ApiOperation(value = "上传视频")
    @PostMapping("upload")
    public Result uploadVideo(@RequestPart MultipartFile file) throws Exception {
        String videoId = aliyunSdkUtils.uploadVideo(file);
        return Result.ok().data("videoId",videoId);
    }

    @ApiOperation(value = "删除视频")
    @DeleteMapping("/{videoId}")
    public Result deleteById(@PathVariable("videoId") String videoId) throws InterruptedException {
        aliyunSdkUtils.deleteVideo(videoId);
        Thread.sleep(1000);
        return Result.ok();
    }

}

